#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int Min = INT_MAX, gain = 0;
        for (auto p : prices)
        {
            Min = min(Min, p);
            gain = max(p - Min, gain);
        }
        return gain;
    }
};